//
//  AboutUsViewController.m
//  CoolTennisBall
//
//  Created by Coollang on 16/7/15.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "AboutUsViewController.h"
#import "NSBundle+CurrentLanguage.h"
#import "UIView+Frame.h"
#import "Masonry/Masonry.h"

#define screenW [UIScreen mainScreen].bounds.size.width

@interface AboutUsViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, weak)IBOutlet UILabel *nameLabel;

@property (nonatomic, strong) UIPageControl *pageControl;

@end

@implementation AboutUsViewController {
    BOOL _isChinese;
    NSArray *_nameTexts;
    CGFloat _imageViewWH; // 二维码图片的款高
    NSString *_publicImageName; //公众号二维码图片
    NSString *_weixinImageName; //微信二维码图片
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (screenW > 375) {
        _imageViewWH = 304;
        _publicImageName = @"公共号750";
        _weixinImageName = @"微信750";
       
    }else {
        _imageViewWH = 216.5;
        _publicImageName = @"公共号640";
        _weixinImageName = @"微信640";
    }
    
    [self configerUpView];
    
}

- (void)configerUpView {

    _isChinese = [NSBundle currentLanguageIsChinese];
    
    
    self.title = NSLocalizedString(@"About Us", nil);
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sport_icon_blackbackArrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    
    self.pageControl.currentPage = 0;
    
    _nameTexts = [NSArray arrayWithObjects:@"官方公众号",@"官方微信号", nil];
    _nameLabel.font = [UIFont systemFontOfSize:24 weight:1.5f];
    
    self.nameLabel.text = _nameTexts[0];
    
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(34);
        make.height.mas_equalTo(_imageViewWH);
    }];
    
    UIImageView *publicImageView = [[UIImageView alloc] init];
    publicImageView.image = [UIImage imageNamed:_publicImageName];
    [self.scrollView addSubview:publicImageView];
    
    [publicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.scrollView);
        make.width.height.mas_equalTo(_imageViewWH);
    }];
    
    UIImageView *weChatImageView = [[UIImageView alloc] init];
    weChatImageView.image = [UIImage imageNamed:_weixinImageName];
    [self.scrollView addSubview:weChatImageView];
    
    [weChatImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollView.mas_left).offset(screenW + (screenW - _imageViewWH) * 0.5);
        make.centerY.equalTo(self.scrollView);
        make.width.height.mas_equalTo(_imageViewWH);
    }];
    
    self.scrollView.contentSize = CGSizeMake(2 * screenW, 0);
    
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    
    
    self.pageControl = [[UIPageControl alloc] init];
    self.pageControl.numberOfPages = _nameTexts.count;
    
    [self.view addSubview:self.pageControl];
    
    [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.scrollView.mas_bottom).offset(62);
    }];
    
    self.pageControl.currentPageIndicatorTintColor = kSelectedColor;
    self.pageControl.pageIndicatorTintColor = [UIColor grayColor];

    
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.pageControl.currentPage = (self.scrollView.contentOffset.x + self.scrollView.frame.size.width * 0.5) / self.scrollView.frame.size.width;
    
    self.nameLabel.text = _nameTexts[self.pageControl.currentPage];
    
}

@end
